home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / comm / misc / DragonDaemon.lha / DragonDaemon-Install / Entwickler / C / infotest.c < prev    next >
C/C++ Source or Header  |  1999-05-17  |  3KB  |  115 lines

  1. /* InfoTest.c
  2. **
  3. ** $VER: InfoTest.c 1.0 (17.5.99)
  4. ** Shows some information in a DragonDaemon requester.
  5. ** Written by Kai Radewald <kai.radewald@stud.uni-hannover.de>
  6. **     for SAS/C v6.58. May work with other compilers as well.
  7. ** This demo program is in the public domain.
  8. ** Please have a look at my homepage [http://browse.to/radewald]
  9. ** DragonDaemon 1.0 is © 1999 Juergen Reinert <ac-techno@t-online.de>
  10. */
  11.  
  12. #include <proto/dos.h>
  13. #include <proto/exec.h>
  14. #include <exec/memory.h>
  15. #include "dragondaemon.h"
  16.  
  17. static const STRPTR VersionTag = "$VER: InfoTest 0.1 " __AMIGADATE__;
  18.  
  19. static struct DD_Message *ddmsg;
  20. static struct MsgPort    *ddreply;
  21.  
  22. /****************************************
  23. ** SEND A COMMAND TO THE DRAGON DAEMON **
  24. ****************************************/
  25.  
  26. LONG Send2Daemon (LONG cmd, LONG arg0, LONG arg1, LONG opt)
  27. {
  28.     /* Local variables */
  29.  
  30.     LONG error = 1;
  31.  
  32.     struct MsgPort *dcrx;
  33.     struct Message *dummy;
  34.  
  35.     /* Fill in the DD_Message structure */
  36.  
  37.     ddmsg->dd_StdMsg.mn_Node.ln_Type = NT_MESSAGE;
  38.     ddmsg->dd_StdMsg.mn_ReplyPort    = ddreply;
  39.     ddmsg->dd_StdMsg.mn_Length       = sizeof (struct DD_Message);
  40.     ddmsg->dd_Command                = cmd;
  41.     ddmsg->dd_Arg0                   = arg0;
  42.     ddmsg->dd_Arg1                   = arg1;
  43.     ddmsg->dd_Options                = opt;
  44.  
  45.     /* Obtain DragonDaemon's public message port */
  46.  
  47.     if (dcrx = FindPort (DD_PORTNAME))
  48.     {
  49.         PutMsg (dcrx, (struct Message*) ddmsg);
  50.         WaitPort (ddreply);
  51.  
  52.         while (dummy = GetMsg (ddreply))
  53.         {
  54.             error = ddmsg->dd_Return;
  55.         }
  56.     }
  57.  
  58.     /* End of function */
  59.  
  60.     return error;
  61. }
  62.  
  63. /******************
  64. ** MAIN FUNCTION **
  65. ******************/
  66.  
  67. int __stdargs main (void)
  68. {
  69.     /* Local variables */
  70.  
  71.     LONG dderr;
  72.  
  73.     /* Allocate memory for DD_Message structure */
  74.  
  75.     if (ddmsg = (struct DD_Message*) AllocVec (sizeof (struct DD_Message), MEMF_CLEAR|MEMF_PUBLIC))
  76.     {
  77.         /* Create reply message port */
  78.  
  79.         if (ddreply = CreateMsgPort ())
  80.         {
  81.             /* Make reply port public */
  82.  
  83.             AddPort (ddreply);
  84.  
  85.             /* Send a command to DragonDaemon */
  86.  
  87.             if (dderr = Send2Daemon (DDCMD_INFO, (LONG) "Dies ist eine Info!", 0, 0))
  88.             {
  89.                 Printf ("DragonDaemon returned error %ld.\n", dderr);
  90.             }
  91.  
  92.             /* Remove port from public list and delete it */
  93.  
  94.             RemPort (ddreply);
  95.             DeleteMsgPort (ddreply);
  96.         }
  97.         else
  98.         {
  99.             PutStr ("Couldn't create message port.\n");
  100.         }
  101.  
  102.         /* Free memory of DD_Message structure */
  103.  
  104.         FreeVec ((APTR) ddmsg);
  105.     }
  106.     else
  107.     {
  108.         PutStr ("No memory for DD_Message structure.\n");
  109.     }
  110.  
  111.     /* That's all folks! ;-) */
  112.  
  113.     return RETURN_OK;
  114. }
  115.